package com.agriculture.common;

public class Response<T> {
    private Integer code;       // 状态码：1成功，0失败
    private String message;     // 提示信息
    private T data;            // 数据

    public Response(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Response<T> success(String message, T data) {
        return new Response<T>(1, message, data);
    }

    public static <T> Response<T> error(String message) {
        return new Response<T>(0, message, null);
    }

    // 添加判断是否成功的方法
    public boolean isSuccess() {
        return code == 1;
    }

    // Getter 和 Setter 方法
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
} 